//
//  HeadSelectCellTableViewCell.m
//  OneCreditTreasure
//
//  Created by iOS Grouper on 16/8/29.
//
//

#import "HeadSelectCellTableViewCell.h"

@interface HeadSelectCellTableViewCell()
@property (nonatomic, strong) UIView *infoView;

@property (nonatomic, strong) UIView *paymentView;
@property (nonatomic, strong) UISegmentedControl *sc;
//期数按钮
@property (nonatomic, strong) UIButton *btn0;
@property (nonatomic, strong) UIButton *btn1;
@property (nonatomic, strong) UIButton *btn2;

@end

@implementation HeadSelectCellTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = LV;
        [self creatView];
        [self infoView];
    }
    
    return self;
}
- (void)changeSelectedState:(UIButton *)sender {
    [self.btn0 setSelected:NO];
    [self.btn1 setSelected:NO];
    [self.btn2 setSelected:NO];
    sender.selected = !sender.isSelected;
}

#pragma mark - 方法 methods
- (void)changePayNum:(UISlider *)sender {
    NSInteger value = sender.value * 10;
    [self.sc setSelectedSegmentIndex:value];
}

- (UIView *)infoView {
    if(_infoView == nil) {
        _infoView = [[UIView alloc] init];
        _infoView.backgroundColor = [UIColor whiteColor];
        [self addSubview:_infoView];
        CGFloat infoViewWidth = kScreenW - 90 * AUTO_WIDTH;
        [_infoView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(0);
            make.top.equalTo(15 * AUTO_HEIGHT);
            make.height.equalTo(140 * AUTO_HEIGHT);
            make.width.equalTo(infoViewWidth);
        }];
        _infoView.layer.borderWidth = 1;
        _infoView.layer.borderColor = [[UIColor lightGrayColor] CGColor];
        
        CGFloat LBWidth = infoViewWidth / 3;
        
        CGFloat LBHeight= 140 * AUTO_HEIGHT / 2;
        //上牌时间LB
        UILabel *firstTimeLB = [UILabel new];
        [_infoView addSubview:firstTimeLB];
        [firstTimeLB mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.equalTo(0);
            make.height.mas_equalTo(LBHeight);
            make.width.equalTo(LBWidth);
        }];
        firstTimeLB.text = @"上牌时间\n2013-05-13";
        myLBSettings(firstTimeLB);
        
        //分割线
        UIView *lineView = [UIView new];
        lineView.backgroundColor = [UIColor lightGrayColor];
        [_infoView addSubview:lineView];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.equalTo(0);
            make.left.equalTo(firstTimeLB.mas_right).equalTo(0);
            make.width.equalTo(1);
        }];
        
        //行使里程LB
        UILabel *longLB = [UILabel new];
        [_infoView addSubview:longLB];
        [longLB mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(0);
            make.height.mas_equalTo(LBHeight);
            make.left.equalTo(lineView.mas_right).equalTo(0);
            make.width.equalTo(LBWidth);
        }];
        longLB.text = @"形式里程\n5万公里";
        myLBSettings(longLB);
        
        //分割线
        UIView *lineView1 = [UIView new];
        lineView1.backgroundColor = [UIColor lightGrayColor];
        [_infoView addSubview:lineView1];
        [lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(longLB.mas_right).equalTo(0);
            make.top.bottom.equalTo(0);
            make.width.equalTo(1);
        }];
        
        //车价LB
        UILabel *priceCarLB = [UILabel new];
        [_infoView addSubview:priceCarLB];
        [priceCarLB mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(lineView1.mas_right).equalTo(0);
            make.top.equalTo(0);
            make.height.mas_equalTo(LBHeight);
            make.right.equalTo(0);
        }];
        priceCarLB.text = @"车价\n50万";
        myLBSettings(priceCarLB);
        
        //横线
        UIView *hLine = [UIView new];
        hLine.backgroundColor = [UIColor lightGrayColor];
        [_infoView addSubview:hLine];
        [hLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(firstTimeLB.mas_bottom);
            make.height.mas_equalTo(1);
            make.left.mas_equalTo(_infoView);
            make.right.mas_equalTo(_infoView);
            
        }];
        
        
        
        _firstPriceL = [UILabel new];
        [_infoView addSubview:_firstPriceL];
        [_firstPriceL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(firstTimeLB);
            make.top.mas_equalTo(hLine.mas_bottom);
            make.height.mas_equalTo(LBHeight);
            make.width.equalTo(LBWidth);
            
        }];
        _firstPriceL.text = @"首付\n22240元";
        myLBSettings(_firstPriceL);
        
        
        _mouthDataL = [UILabel new];
        [_infoView addSubview:_mouthDataL];
        [_mouthDataL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(_firstPriceL);
            make.left.mas_equalTo(lineView.mas_right);
            make.width.mas_equalTo(LBWidth);
            make.height.mas_equalTo(LBHeight);
            
        }];
        _mouthDataL.text = @"期数\n36期";
        myLBSettings(_mouthDataL);
        
        _mouthPriceL = [UILabel new];
        [_infoView addSubview:_mouthPriceL];
        [_mouthPriceL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(_firstPriceL);
            make.height.mas_equalTo(LBHeight);
            make.width.mas_equalTo(LBWidth);
            make.left.mas_equalTo(lineView1.mas_right);
            
        }];
        _mouthPriceL.text = @"月供\n6000元起";
        myLBSettings(_mouthPriceL);
        
        
        
        
    }
    return _infoView;
}


- (void)creatView{
  
            _paymentView = [[UIView alloc] init];
            _paymentView.backgroundColor = [UIColor whiteColor];
            [self addSubview:_paymentView];
            CGFloat paymentViewWidth = kScreenW - 60 * AUTO_WIDTH;
            CGFloat paymentViewHeight = 135 * AUTO_HEIGHT;
            [_paymentView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerX.equalTo(0);
                make.top.equalTo(self.contentView).equalTo(170 * AUTO_HEIGHT);
                make.height.equalTo(paymentViewHeight);
                make.width.equalTo(paymentViewWidth);
            }];
            _paymentView.layer.borderWidth = 1;
            _paymentView.layer.borderColor = [[UIColor lightGrayColor] CGColor];
            _paymentView.layer.cornerRadius = 8 * AUTO_HEIGHT;
            
            //首付滑动选择视图
            UIView *chooseFisrtPayNumView = [UIView new];
            [_paymentView addSubview:chooseFisrtPayNumView];
            CGFloat width = paymentViewHeight / 2 - 1 ;
            [chooseFisrtPayNumView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.top.equalTo(0);
                make.height.equalTo(width);
            }];
            
            UILabel *payTipLB = [UILabel new];
            [chooseFisrtPayNumView addSubview:payTipLB];
            [payTipLB mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(22 * AUTO_WIDTH);
                make.centerY.equalTo(0);
            }];
            payTipLB.text = @"首付";
            payTipLB.font = [UIFont systemFontOfSize:15];
            
            UISegmentedControl *numSC = [[UISegmentedControl alloc] initWithItems:@[@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9"]];
            self.sc = numSC;
            [chooseFisrtPayNumView addSubview:numSC];
            [numSC mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(payTipLB.mas_right).equalTo(8 * AUTO_WIDTH);
                make.top.equalTo(8 * AUTO_HEIGHT);
                make.width.equalTo(220 * AUTO_WIDTH);
                make.height.equalTo(20 * AUTO_HEIGHT);
            }];
            [numSC setSelectedSegmentIndex:0];
            [numSC setTintColor:[UIColor whiteColor]];
            [numSC setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor lightGrayColor]} forState:UIControlStateNormal];
            [numSC setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]} forState:UIControlStateSelected];
            
            UISlider *slider = [[UISlider alloc] init];
            [chooseFisrtPayNumView addSubview:slider];
            [slider mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(payTipLB.mas_right).equalTo(8 * AUTO_WIDTH);
                make.top.equalTo(numSC.mas_bottom).equalTo(8 * AUTO_HEIGHT);
                make.width.equalTo(220 * AUTO_WIDTH);
                make.height.equalTo(20 * AUTO_HEIGHT);
            }];
            [slider addTarget:self action:@selector(changePayNum:) forControlEvents:UIControlEventValueChanged];
            
            //分割线
            UIView *lineView = [UIView new];
            lineView.backgroundColor = [UIColor lightGrayColor];
            [_paymentView addSubview:lineView];
            [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(20 * AUTO_WIDTH);
                make.right.equalTo(-20 * AUTO_WIDTH);
                make.top.equalTo(chooseFisrtPayNumView.mas_bottom).equalTo(0);
                make.height.equalTo(1);
            }];
            
            //期数按钮选择视图
            UIView *payNumView = [UIView new];
            [_paymentView addSubview:payNumView];
            [payNumView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.bottom.equalTo(0);
                make.top.equalTo(lineView.mas_bottom).equalTo(0);
            }];
            
            UILabel *payNumTipLB = [UILabel new];
            [payNumView addSubview:payNumTipLB];
            [payNumTipLB mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(22 * AUTO_WIDTH);
                make.centerY.equalTo(0);
            }];
            payNumTipLB.text = @"期数";
            payNumTipLB.font = [UIFont systemFontOfSize:15];
            
            UIButton *numBtn0 = [UIButton buttonWithType:UIButtonTypeSystem];
            self.btn0 = numBtn0;
            [payNumView addSubview:numBtn0];
            [numBtn0 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(payNumTipLB.mas_right).equalTo(20 * AUTO_WIDTH);
                make.centerY.equalTo(0);
                make.width.equalTo(55 * AUTO_WIDTH);
                make.height.equalTo(30 * AUTO_HEIGHT);
            }];
            [numBtn0 setTitle:@"12" forState:UIControlStateNormal];
            myBtnSettings(1, [[UIColor lightGrayColor] CGColor], [UIColor lightGrayColor], 6 * AUTO_WIDTH, numBtn0);
            [numBtn0 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            if ([self respondsToSelector:@selector(changeSelectedState:)]) {
                [numBtn0 addTarget:self action:@selector(changeSelectedState:) forControlEvents:UIControlEventTouchUpInside];
            }
            
            UIButton *numBtn1 = [UIButton buttonWithType:UIButtonTypeSystem];
            self.btn1 = numBtn1;
            [payNumView addSubview:numBtn1];
            [numBtn1 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(numBtn0.mas_right).equalTo(20 * AUTO_WIDTH);
                make.centerY.equalTo(0);
                make.width.equalTo(55 * AUTO_WIDTH);
                make.height.equalTo(30 * AUTO_HEIGHT);
            }];
            [numBtn1 setTitle:@"24" forState:UIControlStateNormal];
            myBtnSettings(1, [[UIColor lightGrayColor] CGColor], [UIColor lightGrayColor], 6 * AUTO_WIDTH, numBtn1);
            [numBtn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            if ([self respondsToSelector:@selector(changeSelectedState:)]) {
                [numBtn1 addTarget:self action:@selector(changeSelectedState:) forControlEvents:UIControlEventTouchUpInside];
            }
            
            UIButton *numBtn2 = [UIButton buttonWithType:UIButtonTypeSystem];
            self.btn2 = numBtn2;
            [payNumView addSubview:numBtn2];
            [numBtn2 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(numBtn1.mas_right).equalTo(20 * AUTO_WIDTH);
                make.centerY.equalTo(0);
                make.width.equalTo(55 * AUTO_WIDTH);
                make.height.equalTo(30 * AUTO_HEIGHT);
            }];
            [numBtn2 setTitle:@"36" forState:UIControlStateNormal];
            myBtnSettings(1, [[UIColor lightGrayColor] CGColor], [UIColor lightGrayColor], 6, numBtn2);
            [numBtn2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            if ([self respondsToSelector:@selector(changeSelectedState:)]) {
                [numBtn2 addTarget:self action:@selector(changeSelectedState:) forControlEvents:UIControlEventTouchUpInside];
            }
            
            UILabel *tip = [UILabel new];
            [payNumView addSubview:tip];
            [tip mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(numBtn2.mas_right).equalTo(10 * AUTO_WIDTH);
                make.centerY.equalTo(0);
            }];
            tip.text = @"期";
            tip.font = [UIFont systemFontOfSize:15];
            
//        }
//        return _paymentView;
//    }

    
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
